package com.ch04.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @ClassName ServicePostProcessor
 * @Description 自定义后置处理器(BeanPostProcessor)
 * 后置处理器可以在spring容器装配完bean(包括依赖注入)之后,在执行bean的初始化方法前执行
 * 注意: 后置处理器是针对所有的bean
 * @Author Kx
 * @Date 2025/4/28 11:39
 * @Version 1.0
 */
public class ServicePostProcessor implements BeanPostProcessor {
    /** 
     * @author: kx
     * @date: 2025/4/28 11:57
     * @param bean : 正在被初始化的bean实例对象
     * @param beanName : 当前bean在spring容器中的唯一标识符
     * @return java.lang.Object
     * @description: 在bean的初始化方法之前执行
    */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行postProcessBeforeInitialization方法");
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    /***
     * @author: kx
     * @date: 2025/4/28 11:58
     * @param bean : 正在被初始化的bean实例对象
     * @param beanName : 当前bean在spring容器中的唯一标识符
     * @return java.lang.Object
     * @description: 在bean的初始化方法之后执行
    */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("执行postProcessAfterInitialization方法");
        return BeanPostProcessor.super.postProcessAfterInitialization(bean, beanName);
    }
}
